% This script compares US array electric data from 1) direct download and
% 2) from the processed data sent by Gary Egbert. The idea is to make sure
% that my calibration is consistent with that by Gary.


% load MBB03 data from Gary

load('/Users/manojnair/data/usarray/BBdata/data/MBB03c_min.mat')
fday1 = datenum(tsObj.startTime) + datenum(0,0,0,0,0:tsObj.npts-1,0);

% select a small subset of the data

a(1) = datenum('24-Nov-2008 10:29:50');
a(2) = datenum('28-Nov-2008 07:42:13');



javaaddpath('/Users/Shared/Java/mysql-connector-java-5.1.27/mysql-connector-java-5.1.27-bin.jar');
% Make sure that the matlab file irisFetch.m is in the path 
% now get the data directly from iris. LQN is Ex (north component)
data = irisFetch.Traces('EM','MBB03','*','LQN',datestr(a(1),31), datestr(a(2),31));
fday = linspace(data(1).startTime, data(1).endTime, data(1).sampleCount);
% select data in the time of interest
LL = fday1 > a(1) & fday1 < a(2);
% plot the data. Column 4 is Ex
plot(fday1(LL), detrend(tsObj.data(4,LL)),'r');
hold on;
% plot the iris data. Use run mean to minute average the seconds data to be
% consitent with that from gary. Sensitivity is from data. 1e6 for
% converting V/m to mV/km

plot(fday, detrend(runmean(data(1).data/(data(1).sensitivity/1e6),60)));
datetick;

% Both the curves nicely matches. TADA !





